package com.edu.koTA07.takingOrder;

import java.util.Vector;

import com.edu.koTA07.XmlDataSet.BarangXmlDataSet;

import android.graphics.Color;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.TableRow.LayoutParams;

public class ListBarangYangSudahDipesan{
	
	Vector<EditText> editTextList = new Vector<EditText>();
	public ListBarangYangSudahDipesan(final TableLayout tl, AddPesanan addPesanan, BarangXmlDataSet barang, int position)
	{
		//final int bu= 10;
       // for (int current =1; current <bu; current++)
        //{

        	
        	int current=1;
            TableRow tr = new TableRow(addPesanan);
            //set id,start from 1
            tr.setId(current);
            tr.setLayoutParams(new LayoutParams( android.view.ViewGroup.LayoutParams.FILL_PARENT,android.view.ViewGroup.LayoutParams.WRAP_CONTENT)); 

            
           
            // layout remove produk untuk garis hitam
            RelativeLayout layoutRemoveProdukGarisHitam = new RelativeLayout(addPesanan);
            layoutRemoveProdukGarisHitam.setLayoutParams(new LayoutParams(35,android.view.ViewGroup.LayoutParams.FILL_PARENT));
            layoutRemoveProdukGarisHitam.setBackgroundColor(Color.BLACK);
            layoutRemoveProdukGarisHitam.setPadding(1, 0, 0, 1);
            //layout remove produk
            RelativeLayout layoutRemoveProduk = new RelativeLayout(addPesanan);
            layoutRemoveProduk.setBackgroundColor(Color.WHITE);
            layoutRemoveProduk.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,android.view.ViewGroup.LayoutParams.FILL_PARENT));
            // membuat remove button product
            Button button_remove = new Button(addPesanan);
            //button_remove.setId(400+current);
            button_remove.setText("x");
            button_remove.setTextColor(Color.RED);
            button_remove.setPadding(3, 3, 3, 3);
            button_remove.setLayoutParams(new LayoutParams(30,35));
            layoutRemoveProduk.addView(button_remove);
            layoutRemoveProdukGarisHitam.addView(layoutRemoveProduk);
            tr.addView(layoutRemoveProdukGarisHitam);
            final int cur = current;
             button_remove.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                	
					tl.removeViewAt(cur);
					//Intent i = new Intent(ListBarangDipesan.this, ListBarangDipesan.class);
		        	//startActivity(i);
                }
            });   
            
            
            
            
            // layout textview untuk isi produk
            RelativeLayout layoutTextView = new RelativeLayout(addPesanan);
            layoutTextView.setLayoutParams(new LayoutParams(130,android.view.ViewGroup.LayoutParams.FILL_PARENT));
            layoutTextView.setBackgroundColor(Color.BLACK);
            layoutTextView.setPadding(1, 0, 0, 1);
            // membuat textview untuk isi produk
            TextView isi_produk = new TextView(addPesanan);
            isi_produk.setText(barang.getNamaBarang().get(position));
            isi_produk.setTextColor(Color.BLACK);
            isi_produk.setTextSize(10);
            isi_produk.setBackgroundColor(Color.WHITE);
            isi_produk.setPadding(3, 3, 3, 3);
            isi_produk.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,android.view.ViewGroup.LayoutParams.FILL_PARENT));
            layoutTextView.addView(isi_produk);
            tr.addView(layoutTextView);

            
            // layout edit teks untuk garis hitam
            RelativeLayout layoutEditTeksGarisHitam = new RelativeLayout(addPesanan);
            layoutEditTeksGarisHitam.setLayoutParams(new LayoutParams(30,android.view.ViewGroup.LayoutParams.FILL_PARENT));
            layoutEditTeksGarisHitam.setBackgroundColor(Color.BLACK);
            layoutEditTeksGarisHitam.setPadding(1, 0, 0, 1);
            //layout edit teks
            RelativeLayout layoutEditTeks = new RelativeLayout(addPesanan);
            layoutEditTeks.setBackgroundColor(Color.WHITE);
            layoutEditTeks.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,android.view.ViewGroup.LayoutParams.FILL_PARENT));
            // membuat edit teks kuantitas
            EditText isi_kuantitas = new EditText(addPesanan);
            isi_kuantitas.setId(current);
            CharSequence isi_awal="1";
			isi_kuantitas.setText(isi_awal);
            //isi_kuantitas.setPadding(left, top, right, bottom)
            isi_kuantitas.setPadding(3, 3, 3, 3);
            System.out.println(isi_kuantitas.getId());
            isi_kuantitas.setLayoutParams(new LayoutParams(35,35));
            layoutEditTeks.addView(isi_kuantitas);
            layoutEditTeksGarisHitam.addView(layoutEditTeks);
            tr.addView(layoutEditTeksGarisHitam);
            editTextList.add(isi_kuantitas);
            
           
            
	        // layout textview untuk price product
	        RelativeLayout layoutPriceProduct = new RelativeLayout(addPesanan);
	        layoutPriceProduct.setLayoutParams(new LayoutParams(65,android.view.ViewGroup.LayoutParams.FILL_PARENT));
	        layoutPriceProduct.setBackgroundColor(Color.BLACK);
	        layoutPriceProduct.setPadding(1, 0, 0, 1); 
            // membuat text view price product
            TextView isi_price = new TextView(addPesanan);
            //isi_price.setId(500+current);
            isi_price.setText(barang.getHargaBarang().get(position));
            isi_price.setTextColor(Color.BLACK);
            isi_price.setBackgroundColor(Color.WHITE);
            isi_price.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,android.view.ViewGroup.LayoutParams.FILL_PARENT));
            layoutPriceProduct.addView(isi_price);
            tr.addView(layoutPriceProduct);
            
            
            // layout textview untuk subtotal produk
	        RelativeLayout layoutSubtotalProduct = new RelativeLayout(addPesanan);
	        layoutSubtotalProduct.setLayoutParams(new LayoutParams(65,android.view.ViewGroup.LayoutParams.FILL_PARENT));
	        layoutSubtotalProduct.setBackgroundColor(Color.BLACK);
	        layoutSubtotalProduct.setPadding(1, 0, 1, 1);
            // membuat textview subtotal produk
            TextView isi_subtotal = new TextView(addPesanan);
            //isi_subtotal.setId(current);
            isi_subtotal.setText(barang.getHargaBarang().get(position));
            isi_subtotal.setTextColor(Color.BLACK);
            isi_subtotal.setBackgroundColor(Color.WHITE);
            isi_subtotal.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.FILL_PARENT));
            layoutSubtotalProduct.addView(isi_subtotal);
            tr.addView(layoutSubtotalProduct);

            // Add the TableRow to the TableLayout
            tl.addView(tr,current);
       // }
	}
}